import 'package:flutter/material.dart';
import 'package:flutter_app/db/hi_cache.dart';
import 'package:flutter_app/http/core/hi_error.dart';
import 'package:flutter_app/http/dao/login_dao.dart';
import 'package:flutter_app/page/home_page.dart';
import 'package:flutter_app/page/loginpage.dart';
import 'package:flutter_app/page/registerpage.dart';
import 'package:flutter_app/route/route_delegate.dart';
import 'package:flutter_app/utils/color.dart';

import 'http/core/hi_net.dart';
import 'http/request/test_request.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatefulWidget {
  const MyApp({Key key}) : super(key: key);

  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  final BiliRouterDelegate _routerDelegate = BiliRouterDelegate();
  final BiliRouterInfoMationParser _biliRouterInfoMationParser =
  BiliRouterInfoMationParser();

  @override
  Widget build(BuildContext context) {
    var widget = Router(routerDelegate: _routerDelegate,
      routeInformationParser: _biliRouterInfoMationParser,
      routeInformationProvider: PlatformRouteInformationProvider(
          initialRouteInformation: const RouteInformation(location: "/")
      ),
    );
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: white,
      ),
      home: LoginDao(),
      //    home: const MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

// class MyHomePage extends StatefulWidget {
//   const MyHomePage({Key key, this.title}) : super(key: key);
//
//   final String title;
//
//   @override
//   State<MyHomePage> createState() => _MyHomePageState();
// }
//
// class _MyHomePageState extends State<MyHomePage> {
//   void _incrementCounter() async {
//     /*  TestRequest request = TestRequest();
//     try {
//       var result = await HiNet.getInstance().fire(request);
//       print(result);
//     } on NeedAuth catch (e) {
//       print(e);
//     } on NeedLogin catch (e) {
//       print(e);
//     } on HiNetError catch (e) {
//       print(e);
//     }*/
//     login();
//   }
//
//   text() {
//     HiCache.getInstance().setString("key", "存储数据");
//     var keys = HiCache.getInstance().get("key");
//     print(keys);
//   }
//
//   login() async {
//     try {
//       var result = await LoginDao.login("winelx", "zaq1547z");
//       print(result['data']);
//     } on NeedAuth catch (e) {
//       print(e);
//     }
//   }
//
//   @override
//   void initState() {
//     // TODO: implement initState
//     super.initState();
//     HiCache.preInit();
//   }
//
//   @override
//   Widget build(BuildContext context) {
//     return Scaffold(
//         appBar: AppBar(
//           title: Text(widget.title),
//         ),
//         body: const Center(),
//         floatingActionButton: FloatingActionButton(
//           onPressed: _incrementCounter,
//           child: const Icon(Icons.add),
//         ));
//   }
//
// }
